<template>
    <div class="lgbg">
        <div class="login_warp">
            <div class="title">后台管理系统</div>
            <div class="ctl_warp">
                <div class="line">
                    <div class="txt_title">用户名：</div>
                    <div class="txt_ctrl">
                        <el-input v-model="username"></el-input>
                    </div>
                    
                </div>
                <div class="line">
                    <div class="txt_title">密码：</div>
                    <div class="txt_ctrl">
                        <el-input show-password v-model="pwd"></el-input>
                    </div>
                </div>
                <div class="line">
                    <div class="btn_warp">
                        <el-button type="primary" @click="doLogin">登录</el-button>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                username: "admin",
                pwd: '123456'
            }
        },
        methods: {
            doLogin() {
                this.$ums.login({
                    username: this.username,
                    pwd: this.pwd
                }).then(res => {
                    if (200 == res.code) {
                        //跳转画面
                        this.$session.setLoginUser(res.data.admin);
                        
                        let listFinal = [];
                        let listFirst = res.data.listPower.filter(item => item.level == 1);
                        let listSecond = res.data.listPower.filter(item => item.level == 2);
                        for (let first of listFirst) {
                            let children = listSecond.filter(item => item.fkParentId == first.id);
                            if (children && children.length > 0) {
                                first.children = children;
                                listFinal.push(first);
                            }
                            
                        }
                        this.$session.setUserMenu(listFinal);
                        
                        this.$session.loadRoute(listFinal, this.$router);
                        this.$router.push("/layout/main");
                        this.$message.success("登录成功");
                    } else {
                        this.$message.error(res.msg);
                    }
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
.lgbg {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: url("@/assets/images/login_bg.jpg") no-repeat;
    background-size: 100vw 100vh;

    .login_warp {
        width: 40vw;
        height: 37vh;
        border-radius: 5px;
        background: rgba(0, 0, 0, 0.4);
        display: flex;
        flex-direction: column;
        align-items: center;
        color: white;
        .title {
            width: 100%;
            height: 50px;
            line-height: 50px;
            text-align: center;
            margin-top: 30px;
            font-size: 30px;
            font-weight: 800;
            letter-spacing: 10px;
        }

        .ctl_warp {
            width: 100%;
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            
            .line {
                display: flex;
                margin-top: 30px;
                width: 550px;

                .txt_title {
                    width: 150px;
                    height: 40px;
                    line-height: 40px;
                    font-size: 18px;
                    text-align: right;
                    font-weight: 500;
                    letter-spacing: 5px;
                }

                .txt_ctrl {
                    width: 300px;
                }

                .btn_warp {
                    width: 100%;
                    display: flex;
                    justify-content: center;
                }
            }
        }
    }
}
</style>